<template>
  <a-spin :spinning="confirmLoading">
    <a-form ref="formRef" class="antd-modal-form" :labelCol="labelCol" :wrapperCol="wrapperCol">
      <a-row>
        <a-divider type="vertical" class="antd-modal-divider" />
        <h4 class="hClass">产品信息</h4>
      </a-row>
      <a-row>
        <a-col :span="8">
          <a-form-item label="产品名称" v-bind="validateInfos.tailName">
            <a-input v-model:value="formData.tailName" placeholder="" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="产品八位码" :label-col="{ span: 6 }" v-bind="validateInfos.tailCode">
            <a-input v-model:value="formData.tailCode" placeholder="" :disabled="disabled" style="width: 205px !important"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="规格型号" v-bind="validateInfos.tailModel">
            <a-input v-model:value="formData.tailModel" placeholder="" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="产品材质" v-bind="validateInfos.tailMaterial">
            <a-input v-model:value="formData.tailMaterial" placeholder="" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="生产厂家" v-bind="validateInfos.tailFactory">
            <a-input v-model:value="formData.tailFactory" placeholder="" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="生产日期" v-bind="validateInfos.tailDate">
            <a-date-picker placeholder="" v-model:value="formData.tailDate" value-format="YYYY-MM-DD" style="width: 100%" :disabled="disabled" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="产品状态" v-bind="validateInfos.tailState">
            <a-input v-model:value="formData.tailState" placeholder="" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="产品批号" v-bind="validateInfos.tailBatch">
            <a-input v-model:value="formData.tailBatch" placeholder="" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="商标" v-bind="validateInfos.tailBrand">
            <a-input v-model:value="formData.tailBrand" placeholder="" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="原编号" v-bind="validateInfos.tailNumber">
            <a-input v-model:value="formData.tailNumber" placeholder="" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="产品包装" v-bind="validateInfos.tailPackage">
            <!-- <a-input v-model:value="formData.tailPackage" placeholder="" :disabled="disabled"></a-input> -->
            <j-dict-select-tag v-model:value="formData.tailPackage" dictCode="sample_pack" :show-choose-option="false" :disabled="disabled" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="入库日期" v-bind="validateInfos.tailWareDate">
            <a-date-picker placeholder="" v-model:value="formData.tailWareDate" value-format="YYYY-MM-DD" style="width: 100%" :disabled="disabled" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="产品等级" v-bind="validateInfos.tailRank">
            <a-input v-model:value="formData.tailRank" placeholder="" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="存放条件" v-bind="validateInfos.tailStorage">
            <a-input v-model:value="formData.tailStorage" placeholder="" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row>
        <a-divider type="vertical" class="antd-modal-divider" />
        <h4 class="hClass">检验信息</h4>
      </a-row>
      <a-row>
        <a-col :span="8">
          <a-form-item label="检验类别" v-bind="validateInfos.checkType">
            <!-- <a-input v-model:value="formData.checkType" placeholder="" :disabled="disabled"></a-input> -->
            <j-dict-select-tag v-model:value="formData.checkType" dictCode="check_type" :show-choose-option="false" :disabled="disabled" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="样品大类" v-bind="validateInfos.sampleType">
            <a-input v-model:value="formData.sampleTypeId" placeholder="" style="display: none"></a-input>
            <j-dict-select-tag
              v-model:value="formData.sampleTypeId"
              dictCode="lab_items,name,id,type='A'"
              :show-choose-option="false"
              :disabled="disabled"
              @change="handleTypeChange"
              ref="dictSelect"
            />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="样品类别" v-bind="validateInfos.sampleSort">
            <a-input style="display: none" v-model:value="formData.sampleSort"></a-input>
            <a-select v-model:value="formData.sampleSortId" :options="options" @change="handleSortChange" :disabled="disabled"></a-select>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :span="8">
          <!-- <a-form-item label="检测项目" v-bind="validateInfos.testItems">
            <a-select v-model:value="formData.AtestItems" mode="multiple" style="display: none"></a-select>
            <a-select
              v-model:value="formData.AtestItemsIds"
              mode="multiple"
              :options="itemsOptions"
              style="width: 890px"
              :disabled="disabled"
            ></a-select>
          </a-form-item> -->
          <a-form-item label="检测项目" name="testItems">
            <a-select v-model:value="formData.AtestItems" mode="multiple" style="display: none"></a-select>
            <!-- <a-select v-model:value="formData.AtestItemsIds" mode="multiple" :options="options" style="width: 950px"></a-select> -->
            <a-select
              v-model:value="formData.AtestItemsIds"
              mode="multiple"
              placeholder="请选择实验项目"
              option-label-prop="label"
              style="width: 890px"
              :disabled="disabled"
              @change="handleLabItems"
            >
              <a-select-option v-for="item in options1" :value="item.value" :label="item.label">{{ item.labelText }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :span="8">
          <a-form-item label="采购技术规格书" :label-col="{ span: 8 }" v-bind="validateInfos.technical">
            <j-dict-select-tag
              v-model:value="formData.technical"
              dictCode="have_not"
              :show-choose-option="false"
              :disabled="disabled"
              style="width: 180px !important"
            />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="产品合格证" :label-col="{ span: 6 }" v-bind="validateInfos.certificate">
            <j-dict-select-tag
              v-model:value="formData.certificate"
              dictCode="have_not"
              :show-choose-option="false"
              :disabled="disabled"
              style="width: 205px !important"
            />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="产品质量证明书" :label-col="{ span: 8 }" v-bind="validateInfos.quality">
            <j-dict-select-tag
              v-model:value="formData.quality"
              dictCode="have_not"
              :show-choose-option="false"
              :disabled="disabled"
              style="width: 178px !important"
            />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="采购合同" v-bind="validateInfos.contract">
            <a-input v-model:value="formData.contract" placeholder="" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="质量标准附件" :label-col="{ span: 7 }" v-bind="validateInfos.criterionAtta">
            <JUpload v-model:value="formData.criterionAtta" :disabled="disabled"></JUpload>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row>
        <a-divider type="vertical" class="antd-modal-divider" />
        <h4 class="hClass">抽样信息</h4>
      </a-row>
      <a-row>
        <a-col :span="8">
          <a-form-item label="抽样单位" v-bind="validateInfos.spotEntName">
            <a-input v-model:value="formData.spotEntName" placeholder="" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="受检单位" v-bind="validateInfos.entName">
            <a-input v-model:value="formData.entName" placeholder="" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="抽样地点" v-bind="validateInfos.spotAddress">
            <a-input v-model:value="formData.spotAddress" placeholder="" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="抽样时间" v-bind="validateInfos.spotDate">
            <a-date-picker placeholder="" v-model:value="formData.spotDate" value-format="YYYY-MM-DD" style="width: 100%" :disabled="disabled" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="抽样基数" v-bind="validateInfos.spotBase">
            <a-input v-model:value="formData.spotBase" placeholder="" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="抽取样品量" :label-col="{ span: 6 }" v-bind="validateInfos.spotAmount">
            <a-input v-model:value="formData.spotAmount" placeholder="" :disabled="disabled" style="width: 205px !important"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="抽样方式" v-bind="validateInfos.spotWay">
            <a-input v-model:value="formData.spotWay" placeholder="" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="样品储运方式" :label-col="{ span: 7 }" v-bind="validateInfos.spotStoreWay">
            <a-input v-model:value="formData.spotStoreWay" placeholder="" :disabled="disabled" style="width: 192px !important"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="封样形式" v-bind="validateInfos.spotSealed">
            <a-input v-model:value="formData.spotSealed" placeholder="" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="抽样标准" v-bind="validateInfos.spotStandard">
            <a-input v-model:value="formData.spotStandard" placeholder="" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="供方类别" v-bind="validateInfos.spotCategory">
            <a-input v-model:value="formData.spotCategory" placeholder="" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="是否危险品" :label-col="{ span: 6 }" v-bind="validateInfos.riskChemicla">
            <j-dict-select-tag
              v-model:value="formData.riskChemicla"
              dictCode="yn"
              :show-choose-option="false"
              :disabled="disabled"
              style="width: 205px !important"
            />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="备注" v-bind="validateInfos.remark">
            <a-input v-model:value="formData.remark" placeholder="" :disabled="disabled" style="width: 890px !important"></a-input>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row>
        <a-divider type="vertical" class="antd-modal-divider" />
        <h4 class="hClass">其他信息</h4>
      </a-row>
      <a-row>
        <a-col :span="8">
          <a-form-item label="抽样人" v-bind="validateInfos.spotPerson">
            <a-input v-model:value="formData.spotPerson" placeholder="" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="陪同抽样人" :label-col="{ span: 6 }" v-bind="validateInfos.peerSpotPerson">
            <a-input v-model:value="formData.peerSpotPerson" placeholder="" :disabled="disabled" style="width: 205px !important"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="受检单位代表" :label-col="{ span: 7 }" v-bind="validateInfos.entPerson">
            <a-input v-model:value="formData.entPerson" placeholder="" :disabled="disabled" style="width: 190px !important"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="抽样单" name="superviseAtta">
            <JUpload v-model:value="formData.superviseAtta" :disabled="disabled"></JUpload>
          </a-form-item>
        </a-col>
        <!-- <a-col :span="8">
          <a-form-item label="经办人" v-bind="validateInfos.handler">
            <a-input v-model:value="formData.handler" placeholder="" :disabled="disabled"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="经办日期" v-bind="validateInfos.handlDate">
            <a-date-picker placeholder="" v-model:value="formData.handlDate" value-format="YYYY-MM-DD" style="width: 100%"
              :disabled="disabled" />
          </a-form-item>
        </a-col> -->
      </a-row>
      <a-tabs v-show="formData.labSampleList.length > 0" style="margin-bottom: 3px">
        <a-tab-pane tab="样品信息">
          <div style="margin-bottom: 3px">
            <a-row type="flex" style="margin-bottom: 3px">
              <a-col :span="4" style="text-align: center">样品名称</a-col>
              <a-col :span="3" style="text-align: center">抽样单位</a-col>
              <a-col :span="3" style="text-align: center">抽样地点</a-col>
              <a-col :span="3" style="text-align: center">抽样日期</a-col>
              <a-col :span="3" style="text-align: center">样品外观</a-col>
              <a-col :span="3" style="text-align: center">抽样基数</a-col>
              <a-col :span="2" style="text-align: center">样品数量</a-col>
              <a-col :span="3" style="text-align: center">样品编号</a-col>
              <!-- <a-col :span="2" style="text-align: center;">操作</a-col> -->
            </a-row>
            <a-row type="flex" style="margin-bottom: 3px; height: 30px" gutter="1px" v-for="(item, index) in formData.labSampleList" :key="index">
              <a-col :span="2" style="display: none">
                <a-form-item>
                  <a-input v-model:value="item.id" />
                  <a-input v-model:value="item.samStatus" />
                  <a-input v-model:value="item.samType" />
                </a-form-item>
              </a-col>
              <a-col :span="4">
                <a-form-item>
                  <a-input v-model:value="item.samName" style="width: 165px" :disabled="true" />
                </a-form-item>
              </a-col>
              <a-col :span="3">
                <a-form-item>
                  <a-input v-model:value="item.samEnt" style="width: 125px" :disabled="true" />
                </a-form-item>
              </a-col>
              <a-col :span="3">
                <a-form-item>
                  <a-input v-model:value="item.samAddress" style="width: 125px" :disabled="true" />
                </a-form-item>
              </a-col>
              <a-col :span="3">
                <a-form-item>
                  <a-date-picker valueFormat="YYYY-MM-DD" v-model:value="item.samDate" style="max-width: 125px" :disabled="true" />
                </a-form-item>
              </a-col>
              <a-col :span="3">
                <a-form-item>
                  <a-input v-model:value="item.samAppear" style="width: 125px" :disabled="true" />
                </a-form-item>
              </a-col>
              <a-col :span="3">
                <a-form-item>
                  <a-input v-model:value="item.samNumber" style="width: 125px" :disabled="true" />
                </a-form-item>
              </a-col>
              <a-col :span="2">
                <a-form-item>
                  <a-input v-model:value="item.samQuality" style="width: 83px" :disabled="true" />
                </a-form-item>
              </a-col>
              <a-col :span="3">
                <a-form-item>
                  <a-input v-model:value="item.samNum" style="width: 125px" :disabled="true" />
                </a-form-item>
              </a-col>
              <!-- <a-col :span="2">
                <a-form-item>
                  <template v-if="!disabled" style="text-align:center">
                    <Icon icon="ant-design:minus-outlined" @click="delRowCustom(index)"
                      style="font-size: 20px;width: 85px;margin-left: 32px;color: red;" :disabled="disabled" />
                  </template>
                </a-form-item>
              </a-col> -->
            </a-row>
            
            
            <!-- <template v-if="!disabled" style="text-align:center">
              <a-button type="dashed" style="width: 98%; margin-top: 10px;" @click="addRowCustom" :disabled="disabled">
                <Icon icon="ph:plus-bold" />
                添加样品信息
              </a-button>
            </template> -->
          </div>
        </a-tab-pane>
      </a-tabs>
      <a-row style="margin-top:16px;">
        <a-col :span="24">
          <div class="signBox">
            <div class="signBoxLabel" v-if="finallySignUrl">
              <span>审核人：</span>
              <img class="signImg" :src="finallySignUrl" />
            </div>
          </div>
        </a-col>
      </a-row>
    </a-form>
  </a-spin>
</template>

<script lang="ts" setup>
  import { ref, reactive, defineExpose, nextTick, defineProps, computed } from 'vue';
  
  import { useMessage } from '/@/hooks/web/useMessage';
  import JDictSelectTag from '/@/components/Form/src/jeecg/components/JDictSelectTag.vue';
  import JUpload from '/@/components/Form/src/jeecg/components/JUpload/JUpload.vue';
  import { saveOrUpdate, getAduitSign, labSortsList, labSampleList, getExperimentProjects } from '../LabWsupervise.api';
  import { Form, SelectProps } from 'ant-design-vue';

  const props = defineProps({
    formDisabled: { type: Boolean, default: false },
    formData: { type: Object, default: () => {} },
    formBpm: { type: Boolean, default: true },
    auditMark:{ type:String, default: ''},
  });

  const options = ref<SelectProps['options']>([]);
  const options1 = ref<SelectProps['options']>([]);
  const itemsOptions = ref<SelectProps['options']>([]);
  const dictSelect = ref();
  let finallySignUrl = ref('');
  
  const formRef = ref();
  const useForm = Form.useForm;
  const emit = defineEmits(['register', 'ok']);
  const formData = reactive<Record<string, any>>({
    id: '',
    entName: '',
    spotPerson: '',
    peerSpotPerson: '',
    entPerson: '',
    handler: '',
    handlDate: '',
    tailName: '',
    tailCode: '',
    tailMaterial: '',
    tailModel: '',
    tailFactory: '',
    tailDate: '',
    tailState: '',
    tailBatch: '',
    tailPackage: '',
    tailWareDate: '',
    tailRank: '',
    tailStorage: '',
    checkType: '',
    sampleTypeId: '',
    sampleType: '',
    sampleSortId: '',
    sampleSort: '',
    testItemsIds: [],
    testItems: [],
    contract: '',
    criterionAtta: '',
    technical: '',
    certificate: '',
    quality: '',
    spotEntName: '天研院气田开发化学实验室',
    spotAddress: '',
    spotDate: '',
    spotBase: '',
    spotAmount: '',
    spotWay: '',
    spotStoreWay: '',
    spotSealed: '',
    spotCategory: '',
    spotStandard: '',
    remark: '',
    allotStatus: '未分配',
    entrustType: '监督检验',
    carryName: '中国石油西南油气田分公司天然气研究院气田开发化学实验室',
    carryAddress: '四川省成都市天府新区华阳天研路218号 610213',
    carryContact: '印  敬/(028)85604123  13880486175  张楠革/(028)85604594  13618090676',
    codeRule: 'JXY',
    auditMark: '制单中',
    superviseAtta: '',
    sortsList: [],
    itemsList: [],
    labSampleList: [],
    riskChemicla: '',
    tailBrand: '',
    tailNumber: '',
    finalAuditId: '',
    finalAudit: '',
    returnCause: '',
  });
  const { createMessage } = useMessage();
  const labelCol = ref<any>({ xs: { span: 24 }, sm: { span: 5 } });
  const wrapperCol = ref<any>({ xs: { span: 24 }, sm: { span: 16 } });
  const confirmLoading = ref<boolean>(false);
  //表单验证
  const validatorRules = {};
  const { resetFields, validate, validateInfos } = useForm(formData, validatorRules, { immediate: true });

  // 表单禁用
  const disabled = computed(() => {
    if (props.formBpm === true) {
      if (props.formData.disabled === false) {
        return false;
      } else {
        return true;
      }
    }
    return props.formDisabled;
  });

  /**
   * 新增
   */
  function add() {
    edit({});
  }

  /**
   * 编辑
   */
  function edit(record) {
    nextTick(async () => {
      resetFields();
      //赋值
      Object.assign(formData, record);
      let params = { id: formData.id };
      formData.labSampleList = await labSampleList(params);
      finallySignUrl.value = '';
      //编辑或查看进入页面样品大类不为空时，加载样品类型下拉数据
      if (formData.sampleTypeId != null || formData.sampleTypeId != '') {
        const typeId = formData.sampleTypeId;
        let paramsa = { id: typeId };
        formData.sortsList = (await labSortsList(paramsa)).records;
        options.value = [];
        for (let i = 0; i < formData.sortsList.length; i++) {
          options.value.push({
            label: formData.sortsList[i].name,
            value: formData.sortsList[i].id,
          });
        }
      }
      //编辑或查看进入页面样品类型不为空时，加载实验项目下拉数据
      if (formData.sampleSortId != null && formData.sampleSortId != '') {
        //加载实验项目
        loadItems();
      }
      //编辑或查看进入页面加载实验项目下拉数据,并把已有的数据转换成数组
      if (formData.testItemsIds != null || formData.testItemsIds != '') {
        // 将JSON字符串对象转换为对象数组
        if (formData.testItemsIds.length > 0) {
          formData.AtestItemsIds = JSON.parse(formData.testItemsIds);
          formData.AtestItems = JSON.parse(formData.testItems);
        }
      }
      if(formData.finalAuditId!=''){
        getAduitSignList(formData.finalAuditId, 'finallySign');
      }
    });
  }


  //获取初审复审人员电子签名
  const getAduitSignList = async (userId, type) => {
    let parmas = {
      userId: userId,
    };
    let result = await getAduitSign(parmas);
    if (result.success === true) {
      if (result.result) {
        if (type === 'firstSign') {
        } else {
          finallySignUrl.value = result.result;
        }
      }
    }
  };


  //样品大类改变时加载样品类型下拉数据
  async function handleTypeChange() {
    const dictData = dictSelect.value.dictOptions;
    let selectedType = dictData.filter((item) => {
      return item.value === formData.sampleTypeId;
    });
    if (selectedType.length > 0) formData.sampleType = selectedType[0].label;
    const typeId = formData.sampleTypeId;
    let params = { id: typeId };
    //如果样品类型已有选中的数据先清空已选中的数据
    handleClearSort();
    //如果实验项目已有选中的数据先清空已选中的数据
    handleClearItems();

    options1.value = [];
    formData.sortsList = (await labSortsList(params)).records;
    options.value = [];
    for (let i = 0; i < formData.sortsList.length; i++) {
      options.value.push({
        label: formData.sortsList[i].name,
        value: formData.sortsList[i].id,
      });
    }
  }

  //清空已选中的样品类型数据
  function handleClearSort() {
    if (formData.sampleSortId != null || formData.sampleSortId != '') {
      formData.sampleSortId = '';
      formData.sampleSort = '';
    }
  }
  //清空已选中的实验项目数据
  function handleClearItems() {
    if (formData.AtestItemsIds != null || formData.AtestItemsIds != '') {
      formData.AtestItemsIds = [];
      formData.AtestItems = [];
      formData.testItems = '';
      formData.testItemsIds = '';
    }
  }

  //样品类别类改变时
  async function handleSortChange(value, option) {
    formData.sampleSort = option.label;
    //如果实验项目已有选中的数据先清空已选中的数据
    handleClearItems();
    //重新加载实验项目
    loadItems();
  }

  //加载实验项目
  async function loadItems() {
    const SortId = formData.sampleSortId;
    let params = { id: SortId };
    //清空实验项目下拉数据
    formData.itemsList = [];
    //重新给实验项目下拉框赋值
    // formData.itemsList = (await labSortsList(params)).records;
    // itemsOptions.value = [];
    // for (let i = 0; i < formData.itemsList.length; i++) {
    //   itemsOptions.value.push({
    //     label: formData.itemsList[i].name,
    //     value: formData.itemsList[i].id,
    //   });
    // }
    try {
      let result = await getExperimentProjects(params);
      if (result.code === 200) {
        if (result.result.length > 0) {
          formData.itemsList = result.result;
          options1.value = [];
          for (let i = 0; i < formData.itemsList.length; i++) {
            options1.value.push({
              label: formData.itemsList[i].name,
              value: formData.itemsList[i].id,
              labelText: formData.itemsList[i].itemsBasisName,
            });
          }
        }
      }
    } catch (error) {
      createMessage.error(error);
    }
  }
  // 实验项目change事件回到
  const handleLabItems = (value, option) => {
    formData.AtestItems = [];
    if (option.length > 0) {
      option.forEach((element) => {
        formData.AtestItems.push(element.label);
      });
    }
  };
  //把选中的实验项目由数组转成JSON字符串
  function itemsArrayToJson() {
    if (formData.AtestItems != null || formData.AtestItems != '') {
      formData.testItems = JSON.stringify(formData.AtestItems);
      formData.testItemsIds = JSON.stringify(formData.AtestItemsIds);
    }
  }

  // function delRowCustom(index) {
  //   formData['labSampleList'].splice(index, 1);
  //   formData.labSampleList.splice(index, 1);
  // }
  //动态添加行
  // function addRowCustom() {
  //   formData.labSampleList.push({});
  // }

  //生成样品数据
  // function generateSamData(){
  //   formData.labSampleList.samType ="主剂";
  //   formData.labSampleList.samName =formData.tailName;
  //   formData.labSampleList.samEnt  =formData.spotEntName;
  //   formData.labSampleList.samAddress =formData.spotAddress;
  //   formData.labSampleList.samDate =formData.spotDate;
  //   formData.labSampleList.samAppear =formData.tailState;
  //   formData.labSampleList.samNumber =formData.spotBase;
  //   formData.labSampleList.samQuality =formData.spotAmount;
  //   formData.labSampleList.handPerson =formData.spotPerson;
  // }
  /**
   * 提交数据
   */
  async function submitForm() {
    // 触发表单验证
    await validate();
    confirmLoading.value = true;
    const isUpdate = ref<boolean>(false);
    //时间格式化
    let model = formData;
    if (formData.id != null && formData.id != '') {
      isUpdate.value = true;
    }
    itemsArrayToJson();
    await saveOrUpdate(model, isUpdate.value)
      .then((res) => {
        if (res.success) {
          createMessage.success(res.message);
          emit('ok');
        } else {
          createMessage.warning(res.message);
        }
      })
      .finally(() => {
        confirmLoading.value = false;
      });
  }

  defineExpose({
    add,
    edit,
    submitForm,
    formData,
  });
</script>

<style lang="less" scoped>
  .antd-modal-form {
    min-height: 500px !important;
    overflow-y: auto;
    padding: 24px 24px 24px 24px;
  }

  .hClass {
    width: 160px;
    height: 20px;
    font-size: 14px;
    font-family: Microsoft YaHei-Regular, Microsoft YaHei;
    font-weight: 550;
    color: #009688;
    line-height: 14px;
  }

  .ant-form-item-label {
    width: 150px;
    height: 20px;
    font-size: 14px;
    font-family: Microsoft YaHei-Regular, Microsoft YaHei;
    font-weight: 400;
    color: #727272;
    line-height: 20px;
  }

  .ant-input {
    width: 220px;
    height: 32px;
    border-radius: 4px 4px 4px 4px;
    opacity: 1;
    border: 1px solid #dddddd;
  }

  .ant-picker {
    width: 220px !important;
    height: 32px;
    border-radius: 4px 4px 4px 4px;
    opacity: 1;
    border: 1px solid #dddddd;
  }
  .signBox {
    display: flex;
    width: 100%;
  }
  .signBoxLabel {
    margin-right: 50px;
    display: flex;
    padding-left: 20px;
  }
  .signImg {
    width: 200px;
  }
</style>
